package darknet.application.chat.impl.net.message;

import darknet.core.impl.net.AbstractMessage;
import darknet.core.spec.net.MessageHeader;
import darknet.core.spec.net.Node;

/**
 * A channel message.
 * 
 * This message is sent to the node which host a channel.
 * 
 * @author Yoyo
 */
public class ChannelMessage extends AbstractMessage {

    /** The text message */
    private String text;
    
    /** The channel name */
    private String channelName;
    
    /**
     * Initialise a new Channel Message.
     * 
     * @param text The message content
     * @param from The writer
     * @param to   The receiver
     * @param channelName The channel name
     */
    public ChannelMessage(MessageHeader header, Node from, Node to,
            String text, String channelName) {

	super(header, from, to);
	
	if(text == null || text.length() == 0) {
	    throw new IllegalArgumentException("message is invalid");
	}
	this.text = text;
	
	if (channelName == null || channelName.length() == 0) {
	    throw new IllegalArgumentException("channelName is invalid");
	}
	this.channelName = channelName;
    }

    /**
     * Get the text message.
     * @return
     */
    public String getText() {
	return text;
    }
    
    public String getChannelName() {
	return channelName;
    }

    @Override
    public String toString() {

        StringBuilder builder = new StringBuilder("ChannelMessage[");
        builder.append("super=");
        builder.append(super.toString());
        builder.append(", ");
        builder.append("text=");
        builder.append(text);
        builder.append(", ");
        builder.append("channelName=");
        builder.append(channelName);
        builder.append("]");

        return builder.toString();
    }
}
